<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>活动</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="admin.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../module/inventory/css/admin/index.css" />
    <script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
    <script language="javascript" src="../script/Calendar.js"></script>
    <script type="text/javascript" src="../module/inventory/scripts/yui/yahoo-dom-event/yahoo-dom-event.js" ></script>
    <script type="text/javascript" src="../module/inventory/scripts/yui/dragdrop/dragdrop-min.js" ></script>
    <script type="text/javascript" src="../module/inventory/scripts/yui/calendar/calendar-min.js"></script>
    <script type="text/javascript" src="../module/inventory/scripts/index.js"></script>
    <script type="text/javascript" src="../script/jquery.validation.min.js"></script>
    <script src="../script/my_lightbox.js" language="javascript"></script>

    <script>
        $(function(){
            $('#form').validate({
                errorPlacement: function(error, element){
                    element.next('.form-error').append(error);
                },
                rules : {
                    title:{
                        required:true
                    },
                    stime:{
                        required:true
                    },
                    etime:{
                        required:true
                    },
                },
                messages : {
                    title:{
                        required:'请填写标题',
                    },
                    etime:{
                        required:'请填写开始时间',
                    },
                    stime:{
                        required:'请填写结束时间',
                    }
                }
            });
            $('#type').change(function(){
                var s=$(this).val();
                $('span[id^=type_]').hide()
                if(s!=0){
                    $('#type_'+s).show();
                }


            })
        });



    </script>
</head>
<body>
<div class="container">
    <div class="flow">
        <div class="itemtitle">
            <h3>活动</h3>
            <ul>
                <li <{if $smarty.get.operation==''}>class="current"<{/if}>><a href="?m=activity_common&s=activity.php"><span>管理</span></a></li>
                <li <{if $smarty.get.operation=='add'}>class="current"<{/if}>><a href="?m=activity_common&s=activity.php&operation=add"><span>添加</span></a></li>
                <{if $smarty.get.operation=='edit'}>
                <li class="current"><a href="#"><span>修改</span></a></li>
                <{/if}>
            </ul>
        </div>
    </div>
    <div class="h35"></div>
    <{if $smarty.get.operation=='add' or $smarty.get.operation=='edit' }>
    <form name="form" id="form" method="post">
        <input name="id" type="hidden" id="id" value="<{$de.id}>">
        <table class="table">
            <thead>
            <tr>
                <th class="partition" colspan="99">活动</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td width="100">标题</td>
                <td>
                    <input name="title" id="title" type="text" class="w350" value="<{$de.title}>"><div id="form-error" class="form-error"></div>
                </td>
            </tr>

            <tr>
                <td>起止时间</td>
                <td>
                    <script language="javascript">
                        var cdr = new Calendar("cdr");
                        document.write(cdr);
                        cdr.showMoreDay = true;
                    </script>
                    <input onFocus="cdr.show(this);" class="ltext" type="text" name="stime" id="stime" value="<{$de.start_time|date_format}>">
                    <{html_select_time use_24_hours=true display_seconds=false prefix=start time=$de.start_time}>
                    -
                    <input onFocus="cdr.show(this);" class="rtext" type="text" name="etime" id="etime" value="<{$de.end_time|date_format}>">
                    <{html_select_time use_24_hours=true display_seconds=false prefix=end time=$de.end_time}>
                    <div id="form-error" class="form-error"></div>
                </td>
            </tr>
            <tr>
                <td width="100">折扣</td>
                <td>
                    <input name="discount" id="discount" type="text"  value="<{$de.discount}>">
                    <a href="#" title="直接填入折扣率，如7折直接输入0.7"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                </td>
            </tr>
            <tr>
                <td>活动识别码key</td>
                <td>
                    <input type='text' name='key_active' class='' value="<{$de.key_active}>"/>
                </td>
            </tr>
            <tr>
                <td>产品类别ID</td>
                <td>
                    <input type='text' name='cat_ids' class='' value="<{$de.cat_ids}>"/>
                </td>
            </tr>
            <tr>
                <td>关联品牌</td>
                <td>
                    <input type="hidden" name="brandid" class="brandid" value="<{$de.brand_ids}>"/>
                    <input type='text' name='brand' class='brands' value="<{$de.brandname}>" placeholder='输入搜索词' autocomplete="off" style="width: 400px;"/>
                    <a href="#" title="多个用英文逗号分隔"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                    <ul class="brandlist" style="display:none;position:absolute;background-color:#fff;border: 1px solid rgb(207, 201, 201);width: 139px;">
                    </ul>

                </td>
            </tr>
            <tr>
                <td>参与活动的产品ID</td>
                <td>
                    <textarea name='include_ids' rows="4" cols="80"><{$de.include_ids}></textarea>
                    <a href="#" title="多个用英文逗号分隔"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                </td>
            </tr>
            <tr>
                <td>不参与活动的产品ID</td>
                <td>
                    <textarea name='exclude_ids' rows="4" cols="80"><{$de.exclude_ids}></textarea>
                    <a href="#" title="多个用英文逗号分隔"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                </td>
            </tr>
            <tr>
                <td>程序规则</td>
                <td>
                    <textarea name='rule' rows="4" cols="80"><{$de.rule}></textarea>
                </td>
            </tr>
            <tr>
                <td>程序API</td>
                <td>
                    <input name='rule_api' rows="4" cols="80" value="<{$de.rule_api}>"></input>
                </td>
            </tr>
            <tr>
                <td>关联标签</td>
                <td>

                    <select class="w200" name='tags[]' multiple="multiple" size="10" style="height:auto;">
                        <{foreach item=list from=$de.all_tags}>

                        <option <{if $list.stags}> disabled <{/if}> <{if  @$list.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$list.id}>"><{$list.tags}></option>

                        <{foreach item=slist from=$list.stags}>
                        <option <{if $slist.stags}> disabled <{/if}> <{if @$slist.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$slist.id}>">|__<{$slist.tags}></option>

                        <{foreach item=sslist from=$slist.stags}>
                        <option <{if $sslist.stags}> disabled <{/if}> <{if @$sslist.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$sslist.id}>">|____<{$sslist.tags}></option>

                        <{foreach item=lists from=$sslist.stags}>
                        <option <{if @$lists.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$lists.id}>">|______<{$lists.tags}></option>
                        <{/foreach}>
                        <{/foreach}>

                        <{/foreach}>

                        <{/foreach}>
                    </select>
                    按住 “CTRL” 多选
                </td>
            </tr>
            <tr>
                <td>活动描述</td>
                <td>
                    <script charset="utf-8" src="../lib/kindeditor/kindeditor-min.js"></script>

                    <script>
                        var editor;
                        KindEditor.ready(function(K) {
                            editor = K.create('textarea[name="desc"]', {
                                resizeType : 1,
                                allowPreviewEmoticons : false,
                                allowImageUpload : false,
                                langType :'<{$config.language}>',
                            });
                        });
                    </script>
                    <textarea style="width:80%; height:300px" name="desc"><{$de.desc}></textarea>
                </td>
            </tr>
            <tr>
                <td>活动图片</td>
                <td>
                    <input name="pic" class="w350" type="text" id="pic" value="<{$de.pic}>" />
                    [<a href="javascript:uploadfile('上传图片','pic',600,290,'activity')">上传</a>]
                    [<a href="javascript:preview('pic');">预览</a>]
                    [<a onclick="javascript:$('#pic').val('');" href="#">删除</a>] <span class="bz"></span>
                </td>
            </tr>

            <tr>
                <td>展示状态</td>
                <td>
                    <input type="radio" name="status" value="1" id="open" <{if $de.status==1}>checked="checked"<{/if}>/><label for="open">开启</label>
                    <input type="radio" name="status" value="2" id="open" <{if $de.status==2}>checked="checked"<{/if}>/><label for="open">推荐</label>
                    <input type="radio" name="status" value="0" id="close" <{if $de.status==0}>checked="checked"<{/if}>/><label for="close">关闭</label>
                </td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td>
                    <input class="submit" type="submit" value="提交">
                    <input name="act" type="hidden" id="action" value="<{if !$smarty.get.editid}>save<{else}>edit<{/if}>">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
    <script>

        /**通过分类关联品牌
         $('#catid').change(function(){
            	var $$=$(this);
            	if($$.val()==-1){
            		//$('#brandid').html("<option value='-1'>手选单品</option>");
            		return ;
            	}
            	else{

            		<{if $de.brandid && $de.catid}>

                		var sbrand ='&sbrand=<{$de.brandid}>';
                    <{else}>

                    var sbrand ='';
                    <{/if}>

            		$.get('<{$config.weburl}>/admin/module.php?m=activity_common&s=activity.php&operation=getbrand&catid='+$$.val()+sbrand,function(data){
                	//alert	(data);

            			//$('#brandid').html("<option value='-1'>手选单品</option>"+data);

            			$('#brandid').html(""+data);

            		});
            	}
            })
         **/


            //<{if $de.brandid && $de.catid}>

            //$('#catid').change();

            //<{/if}>


        $.each($('[stock]'),function(){
            //alert($(this).attr('stock'));
            var $stock=$(this);

            $.get('<{$config.weburl}>/admin/module.php?m=product&s=inventory_api.php&stock='+$(this).attr('stock'),function(data){
                $stock.html(data);
            });


        });
        $('#related_button').bind('click',function(){
            window.parent.iframe_form("related","选择赠送产品",'<{$config.weburl}>/admin/module.php?m=product&s=products_list.php&type=related', 800, 505);
            return false;
        });

        var rowtypedata = [
            [
                [1, '', 'al'],
                [1, ''],
                [1, ''],
                [1, ''],
                [1, ''],
                [1, ''],
                [1, '<div><a href="javascript:;" class="deleterow" onClick="deleterow(this,{1})">删除</a></div>']

            ]
        ];
        var addrowdirect = 0;
        var addrowkey = 0;
        function addrow(name, type) {

            $('#'+name+'_tr').show();
            var obj=$('#'+name+'_button')[0];
            var table = obj.parentNode.parentNode.parentNode.parentNode;
            var iframe=window.parent.document.getElementById("iframe_"+name).contentWindow;
            var tab=iframe.document.getElementById(name+"_table");
            var checkbox= $(tab).find("input[class='checkitem']:checked");
            var typedata = rowtypedata[type];
            $.each(checkbox,function(i){
                var value1=$("#hidden_"+name).val();
                var value2=this.value
                if(value1.indexOf(','+value2+',') <= 0 )
                {
                    $("#hidden_"+name).val(value1+value2+',');
                    var tr=$(this).parent().parent();
                    if(!addrowdirect) {
                        var row = table.insertRow(obj.parentNode.parentNode.rowIndex);
                    } else {
                        var row = table.insertRow(obj.parentNode.parentNode.rowIndex + 1);
                    }
                    for(var i = 0; i <= typedata.length - 1; i++) {
                        if(i<=6)
                        {
                            var cell = row.insertCell(i);
                            if(i==6)
                            {
                                var tmp = typedata[i][1];
                            }
                            else
                            {
                                var tmp = tr.find('td')[i+1].innerHTML;
                            }
                            if(i==0){
                                cell.className = typedata[i][2];
                            }
                            tmp = tmp.replace(/\{(n)\}/g, function($1) {return addrowkey;});
                            tmp = tmp.replace(/\{(\d+)\}/g, function($1, $2) { return value2+',\''+name+'\''; });
                            cell.innerHTML = tmp;
                        }
                    }
                    addrowkey ++;
                    addrowdirect =0;
                }
            });
        }
        function deleterow(obj,id,name) {
            var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
            var tr = obj.parentNode.parentNode.parentNode;
            var value=$("#hidden_"+name).val();

            var pattern = ','+id+',';
            str = value.replace(new RegExp(pattern), ",");
            $("#hidden_"+name).val(str);
            table.deleteRow(tr.rowIndex);
        }

    </script>
    <{else}>
    <script type="text/javascript">
        $(function(){
            /* 全选 */
            $('.checkall').click(function(){
                var _self = this;
                $('.checkitem').each(function(){
                    if (!this.disabled)
                    {
                        $(this).attr('checked', _self.checked);
                    }
                });
                $('.checkall').attr('checked', this.checked);
            });
        });
    </script>
    <form action="" method="get">
        <input type="hidden" name="m" value="activity">
        <input type="hidden" name="s" value="activity.php">
        <table class="select_table">
            <tbody>
            <tr>
                <td width="50">活动ID:</td>
                <td width="20">
                    <input id="activity_id" class="w50" name="activity_id" type="text" value="<{$smarty.get.activity_id}>" />
                </td>
                <td width="60">活动时间:</td>
                <td class="yui-skin-sam" width="200">
                    <input id="sdate" name="sdate" type="text" size="12" value="<{$smarty.get.sdate}>" onfocus="lockinput(this)" />
                    <input id="edate" name="edate" type="text" size="12" value="<{$smarty.get.edate}>" onfocus="lockinput(this)" />
                    <div id="calContainer" style="display:none; position:absolute;"></div>
                </td>

                <td width="60">是否开始：</td>

                <td width="80">
                    <select name="is_start" id="is_start">
                        <option value="">全部</option>
                        <option value="1" <{if "1"===$smarty.get.is_start}>selected="selected"<{/if}>>正在特卖</option>
                        <option value="2" <{if "2"===$smarty.get.is_start}>selected="selected"<{/if}>>即将特卖</option>
                        <option value="-1" <{if "-1"==$smarty.get.is_start}>selected="selected"<{/if}>>已结束</option>
                    </select>
                </td>

                <td width="70">产品分类:</td>
                <td width="100">
                    <select class="ws350" name='cat'  id="cat">
                        <option value='0'>全部分类</option>
                        <{foreach item=list from=$de.cat}>

                        <option <{if $re.cid==$list.catid || $smarty.get.cat==$list.catid}> selected="selected" <{/if}> value="<{$list.catid}>"><{$list.cat}></option>

                        <{foreach item=slist from=$list.scat}>
                        <option <{if $re.cid==$slist.catid || $smarty.get.cat==$slist.catid}> selected="selected" <{/if}> value="<{$slist.catid}>">|__<{$slist.cat}></option>

                        <{foreach item=lists from=$slist.scat}>
                        <option <{if $re.cid==$lists.catid || $smarty.get.cat==$lists.catid}> selected="selected" <{/if}> value="<{$lists.catid}>">|____<{$lists.cat}></option>
                        <{/foreach}>

                        <{/foreach}>

                        <{/foreach}>
                    </select>
                </td>
                <td width="60">品牌：</td>
                <td>
                    <input type="hidden" name="brandid" class="brandid" value="<{$smarty.get.brandid}>"/>
                    <input style="width:150px;" type='text' name='brand' class='brands' value="<{$smarty.get.brand}>" placeholder='输入搜索词' autocomplete="off"/>
                    <ul class="brandlist" style="display:none;position:absolute;background-color:#fff;border: 1px solid rgb(207, 201, 201);width: 150px;">
                    </ul>
                </td>
                <td width="60">标签：</td>
                <td>
                    <select name="tags">
                        <option value="">选择标签</option>
                        <{foreach item=list from=$de.all_tags}>

                        <option <{if  @$list.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$list.id}>"><{$list.tags}></option>

                        <{foreach item=slist from=$list.stags}>
                        <option  <{if @$slist.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$slist.id}>">|__<{$slist.tags}></option>

                        <{foreach item=sslist from=$slist.stags}>
                        <option <{if @$sslist.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$sslist.id}>">|____<{$sslist.tags}></option>

                        <{foreach item=lists from=$sslist.stags}>
                        <option <{if @$lists.id|in_array:$de.tags}> selected="selected" <{/if}> value="<{$lists.id}>">|______<{$lists.tags}></option>
                        <{/foreach}>
                        <{/foreach}>

                        <{/foreach}>

                        <{/foreach}>
                    </select>
                </td>

                <td width="60">状态：</td>

                <td width="80">
                    <select name="statu" id="statu">
                        <option value="">全部</option>
                        <option value="1" <{if "1"===$smarty.get.statu}>selected="selected"<{/if}>>开启</option>
                        <option value="2" <{if "2"===$smarty.get.statu}>selected="selected"<{/if}>>推荐</option>
                        <option value="0" <{if "0"==$smarty.get.statu}>selected="selected"<{/if}>>关闭</option>
                    </select>
                </td>
                <td><input type="image" src="<{$config.weburl}>/image/admin/search.gif" /></td>
            </tr>

            </tbody>
        </table>
    </form>
    <form action="" method="post">
        <table class="table">
            <thead>
            <tr>
                <th class="partition" colspan="99">活动列表</th>
            </tr>
            </thead>
            <tbody>
            <tr class="header">
                <th width="30"></th>
                <th width="70">显示顺序</th>
                <th width="50">活动ID</th>
                <th>标题</th>
                <th width="150">起止时间</th>
                <!-- <th width="60">申请产品</th> -->

                <th width="170">分类</th>
                <th width="170">品牌</th>
                <th width="160">标签</th>
                <th width="60">状态</th>

                <th width="100">操作</th>
            </tr>
            <{foreach item=list from=$de.list}>
            <tr>
                <td><input type="checkbox" value="<{$list.id}>" class="checkitem" name="chk[]"></td>
                <td><input type="text" class="w50" maxlength="3" name="displayorder[<{$list.id}>]" value="<{$list.displayorder}>" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'')" /></td>
                <td><{$list.id}></td>
                <td <{if $list.pic!=''}>onmouseover="javascript:showOriginImg('<{$list.pic}>');" onmouseout="javascript:hideOriginImg();"<{/if}>><{$list.title}></td>
                <td><{$list.start_time|date_format:"%Y-%m-%d %H:%M"}> <br/> <{$list.end_time|date_format:"%Y-%m-%d %H:%M"}></td>
                <!-- <td>&nbsp;<{if $list.catid==-1}><{$list.num}><{else}>-<{/if}></td> -->
                <td>&nbsp;<{if $list.catid==0}>全分类<{elseif $list.catid==-1}>单品<{else}><{$list.cat}><{/if}></td>
                <td><{$list.brand}></td>
                <td><{$list.tags}></td>
                <td><{if $list.status==1}>开启<{elseif $list.status==2}>推荐<{else}>关闭<{/if}></td>

                <td>
                    <a href="?m=activity_common&s=activity.php&operation=edit&editid=<{$list.id}><{$cond}>"><{$editimg}></a>
                    <!-- <a onclick="return confirm('确定删除吗');" href="?m=activity_common&s=activity.php&delid=<{$list.id}>"><{$delimg}></a>-->
                    <a href='?m=activity_common&s=activity_product_list.php&editid=<{$list.id}><{$cond}>'><{$setimg}></a>

                </td>
            </tr>
            <{foreachelse}>
            <tr>
                <td class="norecord" colspan="99"><i></i><span>暂无符合条件的数据记录</span></td>
            </tr>
            <{/foreach}>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="99">
                    <input type="checkbox" class="checkall" id="del">
                    <input type="hidden" name="act" value="op" />
                    <input type="submit" value="提交" />
                    <div class="page"><{$de.page}></div>
                </td>
            </tr>
            </tfoot>
        </table>
    </form>
    <{/if}>
</div>
<div id="actImgDetail" align="center" style="position:fixed;top:120px;left:40%;display:none;"><img width="560" src="" onerror="this.src='../image/admin/sns_img_fail_min.jpg'" /></div>
</body>
<script>
    $(function(){
        //默认待选品牌
        $('.brands').bind('click',function(e){
            $.get('<{$config.weburl}>/admin/module.php?m=activity_common&s=activity.php&operation=getbrand&brandname=',function(data){
                $('.brandlist').show();
                $('.brandlist').html(""+data);
            });
        });
        //直接搜品牌
        $('.brands').bind('input',function(e){
            var value=$(this).val();
            if(value==''){
                $('.brandlist').hide();
                return ;
            }
            else{
                $.get('<{$config.weburl}>/admin/module.php?m=activity_common&s=activity.php&operation=getbrand&brandname='+value,function(data){
                    $('.brandlist').show();
                    $('.brandlist').html(""+data);
                });
            }
        });
        $('body').bind('click',function(e){
            $('.brandlist').hide();
        });
        $('.brandlist').delegate('li','click',function(){
            var _this=$(this);
            var brandName=_this.text();
            var brandId=_this.attr('bid');

            var selectedBrandName =  $('.brands').val();
            var selectedBrandId =  $('.brandid').val();

            brandName = selectedBrandName+ "," + brandName;
            brandId = selectedBrandId+ "," + brandId;

            brandName = brandName.toString().replace( /^,+/, "" ).replace( /,+$/, "" );;
            brandId = brandId.toString().replace( /^,+/, "" ).replace( /,+$/, "" );;

            $('.brands').val(brandName);
            $('.brandid').val(brandId);

            $('.brandlist').hide();
        });


    });
    //展示分享图片原图
    function showOriginImg(src){
        var actImgDetail = $("#actImgDetail");
        actImgDetail.find('img').attr('src',src+"/560");
        actImgDetail.show();
    }
    //隐藏分享图片原图
    function hideOriginImg(){
        $("#actImgDetail").hide();
    }
</script>
</html>